<script>
  Helpy.topicID = <%= @topic.id %>;
</script>
<div class="pull-right">
  <span class="btn-group left-col-dropdown">
    <%= link_to content_tag(:span, '', class: 'fas fa-ellipsis-v ticket-ellipsis btn'), '#', class: 'dropdown-toggle', data: { toggle: 'dropdown' }%>
    <ul class="dropdown-menu dropdown-menu-right" role="menu">
      <li><%= link_to t('change_owner', default: 'Change author'), '#', data: { toggle: "modal", target: "#change-user-modal-#{first_post_id(@topic)}" } if @topic.posts.present? %></li>
      <hr/>
      <% if @topic.user.present? %>
      <li class="dropdown-header"><%= @topic.user.name %></li>
      <li><%= link_to t(:tickets, default: 'Tickets'), remote: true %></li>
      <li><%= link_to t(:open_new_discussion, default: 'Open Discussion'), new_admin_topic_path(user_id: @topic.user.id), remote: true, class: '' if tickets? %></li>
      <li><%= link_to t(:edit_user, default: 'Edit User'), edit_admin_user_path(@topic.user), remote: false if @topic.user.can_be_edited? current_user %></li>
      <% end %>
    </ul>
  </span>
</div>
<span class="btn-group left-col-dropdown">
  <button class="status dropdown-toggle ticket-control" data-toggle="dropdown" aria-expanded="false">
    <%= control_for_status(@topic.current_status) %>
  </button>
  <ul class="dropdown-menu ticket-controls" role="menu">
    <li><%= link_to t(:mark_closed, default: 'Mark Closed'), admin_update_topic_path(topic_ids: { "":@topic.id }, change_status: 'closed', status: @status), :remote => true, class: 'key-sr' unless @topic.current_status == "closed" %></li>
    <li><%= link_to t(:reopen, default: 'Reopen'), admin_update_topic_path(topic_ids: { "":@topic.id }, change_status: 'reopen', status: @status), :remote => true, class: 'key-so' unless @topic.current_status == "open" %></li>
    <li><%= link_to t(:mark_new, default: 'Mark New'), admin_update_topic_path(topic_ids: { "":@topic.id }, change_status: 'new', status: @status), :remote => true, class: 'key-sn' unless @topic.current_status == "new" %></li>
    <li><%= link_to t(:mark_spam, default: 'Mark Spam'), admin_update_topic_path(topic_ids: { "":@topic.id }, change_status: 'spam', status: @status), :remote => true, class: 'key-ss' unless @topic.current_status == "spam" %></li>
    <li><%= link_to t(:trash, default: 'Trash'), admin_update_topic_path(topic_ids: { "":@topic.id }, change_status: 'trash', status: @status), :remote => true, class: 'key-st' unless @topic.current_status == "trash" %></li>
  </ul>
</span>

<% if forums? %>
  <span class="status privacy btn-group left-col-dropdown">
    <button class="privacy-toggle dropdown-toggle ticket-control" data-toggle="dropdown" aria-expanded="false">
      <%= control_for_privacy(@topic.private?) %>
    </button>
    <ul class="dropdown-menu ticket-controls" role="menu">
      <% Forum.where(private: false).alpha.each do |forum| %>
      <li><%= link_to "#{t(:move_to, default: "Move")}: #{forum.name}", admin_toggle_privacy_path(topic_ids: { "":@topic.id }, private: 'false', forum_id: forum.id, status: @status), :remote => true %></li>
      <% end %>
      <li><%= link_to "#{t(:mark_as, default: "Mark")}: Private", admin_toggle_privacy_path(topic_ids: { "":@topic.id }, private: 'true', forum_id: 1, status: @status), :remote => true %></li>
    </ul>
  </span>
<% end %>

<% unless @topic.current_status == "closed" %>
  <span class="status btn-group left-col-dropdown">
    <button class="dropdown-toggle ticket-control" data-toggle="dropdown" aria-expanded="false">
      <%= content_tag :span, class: 'btn status-label-button label label-warning assign-to' do %>
        <%= @topic.assigned_user.try(:name).try(:upcase) || t(:unassigned, default: 'UNASSIGNED') %>
        <%= content_tag(:i, nil, class: 'caret') + ' ' %>
      <% end %>
    </button>
    <ul class="dropdown-menu ticket-controls" role="menu">
      <li><%= link_to "#{current_user.name.titleize}", admin_assign_agent_path(topic_ids: { "":@topic.id }, assigned_user_id: current_user.id, status: @status), :remote => true unless @topic.current_status == "closed" %></li>
      <li role="separator" class="divider"></li>
      <% (@admins-[current_user]).each do |admin| %>
      <li><%= link_to "#{admin.name.titleize} (#{admin.active_assigned_count})", admin_assign_agent_path(topic_ids: { "":@topic.id }, assigned_user_id: admin.id, status: @status), :remote => true unless @topic.current_status == "closed" %></li>
      <% end %>
      <hr/>
      <li><%= link_to t(:unassign_agent, default: "Unassign Agent"), admin_unassign_agent_path(topic_ids: { "":@topic.id }, assigned_user_id: '', status: @status), :remote => true %></li>
    </ul>
  </span>

  <span class="status btn-group left-col-dropdown">
    <button class="dropdown-toggle ticket-control" data-toggle="dropdown" aria-expanded="false">
      <%= content_tag(:span, style: badge_color_from_topic(@topic), class: "btn status-label-button group-to label label-#{@topic.team_list.present? ? @topic.team_list.first.first.downcase : 'default'}") do %>
        <%= @topic.team_list.first.try(:upcase) || t(:no_team_assigned, default: 'Assign to group') %>
        <%= content_tag(:i, nil, class: 'caret') + ' ' %>
      <% end %>
    </button>
    <ul class="dropdown-menu ticket-controls team-list" role="menu">
      <% @all_teams.to_a.each do |team| %>
        <li class='team-item'>
          <% unless @topic.current_status == "closed" %>
            <%= link_to(color_sample(team), admin_assign_team_path(topic_ids: { "":@topic.id }, assign_team: team, status: @status), :remote => true) %>
          <% end %>
        </li>
      <% end %>
      <hr/>
      <li><%= link_to t(:unassign_from_team, default: "Unassign from group"), admin_unassign_team_path(topic_ids: { "":@topic.id }, team: '', status: @status), :remote => true unless @topic.current_status == "closed" %></li>

    </ul>
  </span>

  <span class="status btn-group left-col-dropdown">
    <button class="dropdown-toggle ticket-control tag-toggle" aria-expanded="false">
      <%= content_tag :span, class: 'btn label-light status-label-button label' do %>
        <%= tags_button_label %>
        <%= content_tag(:i, nil, class: 'caret') + ' ' %>
      <% end %>
    </button>
    <ul class="dropdown-menu ticket-controls" role="menu">
      <li class="dropdown mega-dropdown">
        <span class="topic-tag-form">
          <style>
            .selectize-input {
              border: 1px;
              font-weight: normal;
              text-transform: uppercase;
            }
        
            .selectize-input .item {
              background-color: #ddd;
              color: #666;
            }

            .selectize-control.form-control.select.optional.multi {
              width: 280px;
            }
          </style>
          <%= topic_tag_form %>
        </span>
      </li>
    </ul>
  </span>
<% end %>
